package com.tbit.main.service.impl;

import com.tbit.main.dao.log.MachineLastUseLogDao;
import com.tbit.main.pojo.MachineLastUseLog;
import com.tbit.main.service.MachineLastUseLogService;
import com.tbit.main.util.StringUtil;
import org.apache.commons.collections4.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author LMY
 * @create 2021-01-11 10:26
 * 设备最后扫码日志
 */
@Service("machineLastUseLogService")
public class MachineLastUseLogServiceImpl implements MachineLastUseLogService {

    @Autowired
    private MachineLastUseLogDao machineLastUseLogDao;

    @Override
    public void insert(MachineLastUseLog machineLastUseLog) {
        machineLastUseLogDao.insert(machineLastUseLog);
    }

    @Override
    public void delete(List<Integer> machineLastUseLogId) {
        machineLastUseLogDao.delete(StringUtil.getListString(machineLastUseLogId));
    }

    @Override
    public List<MachineLastUseLog> query(Integer machineId) {
        return machineLastUseLogDao.query(machineId);
    }

    @Override
    public List<Integer> getByMachineNoCount() {
        return machineLastUseLogDao.getByMachineNoCount();
    }

    @Override
    public void deleteMachineId(List<Integer> machineId) {
        List<List<Integer>> machineIds = ListUtils.partition(machineId, 50);
        for (List<Integer> machine : machineIds) {
            machineLastUseLogDao.deleteMachineId(StringUtil.getListString(machine));
        }
    }
}
